﻿Imports Axial
Imports Axial.DOM

Partial Public Class DomEvent
    Inherits System.Web.UI.Page

    Public Sub Startup()
        pnlTest.AddHandler(ClientEvent.MouseDown, AddressOf AlertSomething)
    End Sub

    Public Function AlertSomething(ByVal e As Axial.DOM.Event) As Boolean
        Window.Alert("Cursor X: " + GetPosition(e).X)
        Return True
    End Function

    Public Function GetPosition(ByVal e As Axial.DOM.Event) As Point
        If e Is Nothing Then
            e = Window.Event
        End If

        Dim cursor As New Point
        cursor.X = 0
        cursor.Y = 0
        ' TODO: fix e.PageX <> Nothing
        If e.PageX.HasValue Then
            cursor.X = e.PageX.Value
            cursor.Y = e.PageX.Value
        Else
            cursor.X = e.ClientX + Document.ScrollLeft - Document.DocumentElement.ClientLeft
            cursor.Y = e.ClientY + Document.ScrollTop - Document.DocumentElement.ClientTop
        End If

        Return cursor
    End Function

End Class

Public Structure Point
    Public X As Integer
    Public Y As Integer
End Structure